<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('出租房管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="deptId" name="deptId">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                登录名称：<input type="text" name="loginName"/>
                            </li>
                            <li>
                                手机号码：<input type="text" name="phonenumber"/>
                            </li>
                            <li>
                                用户状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                       name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                       name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var prefix = ctx + "housingManage";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryUserList();
    });

    function queryUserList() {
        var options = {
            url: prefix + "/findRentHousingList",
            uniqueId: "housingId",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/rentHousingEdit/{id}?type=0",
            sortOrder: "desc",
            modalName: "出租房源操作",
            columns: [{
                checkbox: true
            },
                {
                    field: 'rentResidentialName',
                    title: '小区名'
                },
                {
                    field: 'measure',
                    title: '面积(平方米)'
                },
                {
                    field: 'floor',
                    title: '楼层'
                },
                {
                    field: 'renovation',
                    title: '装修风格'
                },
                {
                    field: 'louhu',
                    title: '楼户'
                },
                {
                    field: 'orientation',
                    title: '朝向'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'rentCallName',
                    title: '称呼'
                },
                {
                    field: 'priceMonth',
                    title: '租金（元/月）'
                },
                {
                    field: 'roomNum',
                    title: '室'
                },
                {
                    field: 'officeNum',
                    title: '厅'
                },
                {
                    title: '是否成交',
                    field: 'isDeal',
                    width: '10%',
                    align: "left",
                    formatter: function (value, item, index) {
                        if (value == '0') {
                            return '<span class="label label-info">未成交</span>';
                        }
                        else if (value == '1') {
                            return '<span class="label label-success">已成交</span>';
                        }
                    }
                },
                {
                    title: '修改成交状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusIsDeal(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.isDeal == '0') {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editTabTitle(\'' + row.housingId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="toVoidHousing(\'' + row.housingId + '\')">作废</a> ');
                        }
                        else if (row.isDeal == '1') {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editTabTitle(\'' + row.housingId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }

                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    }

    function statusIsDeal(row) {
        if (row.isDeal == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.housingId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\"></i> ';
        }
    }

    /* 用户管理启用 */
    function enable(housingId) {
        $.modal.confirm("确认要修改为已成交吗？", function() {
            $.operate.post(ctx + "sell/changeIsDeal", { "housingId": housingId, "isDeal": 1 });
        })
    }

    function toVoidHousing(housingId){

        $.modal.confirm("确定作废吗？", function() {
            var data = { "housingId": housingId };
            $.operate.submit(ctx + "housingManage/toVoidHousing", "post", "json", data);
        });
    }


</script>
</body>
</html>